/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class MinimumVariancePartition {
public:
    double minDev(vector <int> mixedSamples, int k);
};
vector< Int > samples;
int sz;
const double INF = 1e10;

template< class T >
T myAbs(T a) {
    return (a < (T)0 ? -a : a ) ;
}
template< class T >
T myMin(T a, T b) {
    return ( a < b ? a : b ) ;
}
int vis[51][51];
double dp[51][51];

inline double calc(int lo, int hi) {
    double sum=0;
    for (int i=lo;i<=hi;++i) {
        sum+=samples[i];
    }
    double mean = sum/( (hi-lo)+1 );


    sum=0;
    for (int i=lo;i<=hi;++i) {
        double var = mean-samples[i];
        sum+= (var*var);
    }
    return sum/( (hi-lo)+1 );
}
double go( int id, int kk) {
    if ( kk < 0 )return INF;


    if ( id==sz ) {
        return kk==0 ? 0. : INF ;
    }
    if ( vis[id][kk]!=-1 ) {
        return dp[id][kk];
    }

    vis[id][kk]=1;
    double best = INF;
    for (int i=id,j=1;i<sz;++i,++j) {
        double tmp = calc(id,i) +go(i+1,kk-1);
        best = myMin( best, tmp );
    }
    return dp[id][kk]=best;
}

double MinimumVariancePartition :: minDev(vector <int> mixedSamples, int k) {
    double retval=0;

    samples.clear();
    sz = SZ( mixedSamples );
    fo(i,sz) {
        samples.pb( (Int)mixedSamples[i] );
    }
    sort(samples.begin(),samples.end(), less<Int>());
    SET(vis,-1);
    retval = go( 0, k );
    printf("RESULT %.9lf\n",retval);
    return retval;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <int> p0, int p1, bool hasAnswer, double p2) {
    cout << "Test " << testNum << ": [" << "{";
    for (int i = 0; int(p0.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << p0[i];
    }
    cout << "}" << "," << p1;
    cout << "]" << endl;
    MinimumVariancePartition *obj;
    double answer;
    obj = new MinimumVariancePartition();
    clock_t startTime = clock();
    answer = obj->minDev(p0, p1);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p2 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == answer && fabs(p2 - answer) <= 1e-9 * max(1.0, fabs(p2));
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    vector <int> p0;
    int p1;
    double p2;

    {
        // ----- test 0 -----
        int t0[] = {3,4,7,10};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 1;
        p2 = 7.5;
        all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        int t0[] = {1000,500,1,500};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 3;
        p2 = 0.0;
        all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        int t0[] = {54,653,876,2,75};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 5;
        p2 = 0.0;
        all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        int t0[] = {42,234,10,1,123,545,436,453,74,85,34,999};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 5;
        p2 = 1700.7397959183672;
        all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 4 -----
        int t0[] = {923,456,12,12,542,234,11,12,10,9};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 4;
        p2 = 1850.3333333333333;
        all_right = KawigiEdit_RunTest(4, p0, p1, true, p2) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
